/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-06-10
 * Time: 21:17
 */
public class test1 {
    public ListNode reverseList(ListNode head) {
        if(head==null || head.next==null){
            return head;
        }
        ListNode cur = head.next;
        head.next = null;
        while(cur!=null){
            ListNode curNext = cur.next;
            cur.next = head;
            head = cur;
            cur =curNext;
        }
        return head;
    }

    class ListNode{
        int val;
        ListNode next;

        ListNode(){

        }

        ListNode(int val){
            this.val = val;
        }

        ListNode(int val,ListNode next){
            this.val = val;
            this.next = next;
        }
    }
}
